Hi everyone,
During the Office Hours webinar, we got a solid question about scripting visibility controls in KeyShot. We didn’t have time to address it live, so I’m sharing a breakdown here with a few example scripts you can use directly or adapt for your workflow.
The Question
What scripting commands can I use to make specific groups visible and hide others?
The Short Answer
To control visibility in KeyShot scripts, the core commands are:
node.hide()
– hides a nodenode.show()
– makes a node visiblenode.isHidden()
– returns the current visibility state
You can use these with different node types (model sets, groups, geometry nodes) depending on how your scene is structured.
Visibility Use Cases with Script References
Each of these examples corresponds directly to a script you can run in KeyShot Python.
1. Hide or Show a Node by Name
Use this to control visibility of any object with a known name.
Use the scripts:
Show Node by Name.py
(for showing)Hides Node by Name.py
(for hiding)
These scripts search the root of the scene for matching node names and toggle visibility accordingly.
Run as-is
Open the script, change the "ground"
node name to match your object, and run:
# From Show Node by Name.py
set_node_visibility_by_name("ground", action="show")
# From Hides Node by Name.py
hide_node_by_name("ground")
2. Activate a Specific Model Set by Name
Use this when you want to display only one model set and hide the rest.
Use the script:
Hide and Show Model Sets.py
This script uses lux.setModelSets()
to make one named model set active.
Run as-is
Change the model set name (e.g. "ground"
) in the script and run it:
# From Hide and Show Model Sets.py
set_active_model_set("ground")
If the name is valid, it activates that set and hides all others.
3. Show or Hide All Model Sets (GUI)
Use this to toggle visibility of all model sets via a checkbox dialog.
Use the script:
Hide Show Model Sets GUI Toggle.py
This script opens a dialog where you can show or hide every model set in the scene at once.
Run as-is
No code changes needed. Just run the script and use the checkbox to control visibility.
# GUI auto-runs main() when script is launched
Internally, it uses:
lux.setModelSets([...]) # Show all
lux.setModelSets([]) # Hide all
4. Show or Hide Children Inside Model Sets (GUI)
Use this when you want to toggle visibility of contents inside model sets, not the sets themselves.
Use the script:
Hide Show Children GUI Toggle.py
This script uses a GUI to loop through every model set and toggle the visibility of its children.
Run as-is
Just run the script and check/uncheck the box to show or hide all model set children.
# GUI auto-runs main() when script is launched
Useful for batch-cleanup or organizing complex scenes.
Behavior Notes and Gotchas
Model Sets vs. Node Visibility
lux.setModelSets()
only affects active sets. Even if nodes inside an inactive set are marked as visible, they won’t render.
Accessing Inactive Sets
Scripts that traverse the full scene tree (like Hide Show Children GUI Toggle.py
) can still access model sets even if they’re not active.
Name Matching Isn’t Recursive
find(name="...")
only searches direct children unless you build a deeper loop. If you’re not seeing results, make sure the node is at the root level or adjust the search method.
These scripts are provided for educational and production use. You’re free to modify them to fit your workflow — or run them as-is for quick results.
# AUTHOR LUX DT ChatGPT
# VERSION 1.4.1
# GUI Script to Toggle Hide or Unhide All Model Set Children Using a Checkbox
import lux
def toggle_model_sets_contents(hide=True):
"""
Hides or unhides all child nodes of model sets based on 'hide' boolean.
"""
root_node = lux.getSceneTree()
for node in root_node.getChildren():
if node.isModelSet():
for child in node.getChildren():
if hide:
child.hide()
else:
child.show()
state = "Hidden" if hide else "Shown"
print(f"✔ {state} children in model set: {node.getName()}")
def main():
# Correct checkbox dialog using DIALOG_CHECK
values = [
("hide_children", lux.DIALOG_CHECK, "Hide Model Set Children?", True)
]
opts = lux.getInputDialog(
title="Model Set Visibility Toggle",
desc="Use the checkbox to toggle visibility of model set children.",
values=values,
id="model_set_checkbox_toggle"
)
if opts and "hide_children" in opts:
toggle_model_sets_contents(hide=opts["hide_children"])
else:
print("⚠️ Dialog canceled or missing input.")
# Run the main GUI function
main()
# AUTHOR: Donald Tuttle, Updated by LUX DT ChatGPT
# VERSION: 2.3.0
# OBJECTIVE: Show or Hide all Model Sets via GUI Checkbox using setModelSets()
import lux
def set_model_sets_visibility(show=True):
"""
Show or hide all model sets.
If `show` is True, activates all model sets.
If `show` is False, clears the active model sets (hides all).
"""
root = lux.getSceneTree()
model_sets = [node for node in root.getChildren() if node.isModelSet()]
all_names = [node.getName() for node in model_sets]
if show:
success = lux.setModelSets(all_names)
if success:
print(f"✅ Showing all {len(all_names)} model sets.")
else:
print("⚠ Failed to show model sets.")
else:
success = lux.setModelSets([]) # Hide all
if success:
print("🔻 All model sets hidden.")
else:
print("⚠ Failed to hide model sets.")
def main():
values = [
("show_sets", lux.DIALOG_CHECK, "Show All Model Sets?", True)
]
opts = lux.getInputDialog(
title="Show/Hide Model Sets",
desc="Check to show all model sets. Uncheck to hide all.",
values=values,
id="show_hide_modelsets_checkbox"
)
if opts and "show_sets" in opts:
set_model_sets_visibility(show=opts["show_sets"])
else:
print("⚠️ Dialog cancelled or no input provided.")
# Run it
main()
# AUTHOR: LUX DT ChatGPT
# VERSION: 1.2.0
# Objective: Hide or Show a Node in the Scene by Name
import lux
def set_node_visibility_by_name(node_name, action="hide"):
"""
Hides or shows all nodes matching the provided name.
action: 'hide' or 'show'
"""
root_node = lux.getSceneTree()
nodes = root_node.find(name=node_name)
if not nodes:
print(f"⚠ No nodes found with the name '{node_name}'.")
return
for node in nodes:
if action.lower() == "hide":
node.hide()
print(f"🔻 Node '{node.getName()}' has been hidden.")
elif action.lower() == "show":
node.show()
print(f"✅ Node '{node.getName()}' is now visible.")
else:
print(f"❌ Invalid action '{action}'. Use 'hide' or 'show'.")
# Example usage:
# Change "ground" to the name of your node
# Set action to "show" or "hide"
set_node_visibility_by_name("ground", action="show")
# AUTHOR: Donald Tuttle
# VERSION: 2.6.0
# OBJECTIVE: Activate (show) all model sets in the scene
import lux
def reactivate_all_model_sets():
root = lux.getSceneTree()
model_sets = [node for node in root.getChildren() if node.isModelSet()]
all_names = [node.getName() for node in model_sets]
if not all_names:
print("⚠ No model sets found in the scene.")
return
success = lux.setModelSets(all_names)
if success:
print(f"✅ Activated {len(all_names)} model sets:")
for name in all_names:
print(f" - {name}")
else:
print("❌ Failed to activate model sets.")
# Run it
reactivate_all_model_sets()
Note: These example scripts are not Official KeyShot scripts and therefore they do not include any support.
Thanks again for the great question.